﻿<%@ Page Language="C#" MasterPageFile="~/Masters/WithoutPermBasic.Master" AutoEventWireup="true" CodeBehind="ProductOrderDetail.aspx.cs" Inherits="PMS.UI.PM.ProductOrderDetail" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <script type="text/javascript">
        $(function () {
            var rowData;
            var height = $("#divTotal").height();
            var content = parseFloat(height) - 130;
            $("#tbList").css("height", content);
            loadTopForm();
            
        });
    </script>

    <script type="text/javascript">
        //加载头部表单
        function loadTopForm() {
            var paramID = com.get.ID;
            var action = com.get.action;
            // 查看，由主表跳转
            if (action == "edit") {
                $.ajax({
                    type: "POST", dataType: "json",
                    url: "/Logic/PM/ProductOrderAjax.aspx?method=GetProductOrderByID&id=" + paramID,
                    success: function (data) {
                        $("#form1").form("load", data);
                    }
                })
            }
            else if (action == "add") {
                paramID = com.get.quotID;
                $.ajax({
                    type: "POST", dataType: "json",
                    url: "/Logic/PM/ProductOrderAjax.aspx?method=GetProductOrderByID&quotID=" + paramID,
                    success: function (data) {
                        $("#form1").form("load", data);
                        $('#IsUrgent').combobox('setValue', '0');
                    }
                })
            }
        }
    </script>

    <script type="text/javascript">
        // 加载产品细则
        $(function () {
            var quotationID = com.get.quotID;
            var action = com.get.action;
            $("#tbList").datagrid({
                url: '/Logic/CM/QuotationAjax.aspx?method=GetAllProductDetailByID',
                queryParams: { "quotID": quotationID },
                loadMsg: '数据加载中请稍后……',
                rownumbers: true,
                showFooter: true,
                pagination: true,
                singleSelect: true,
                pageSize: 20,
                pageList: [10, 20, 50],
                striped: true,
                columns: [[
                    { field: 'ck', checkbox: true, width: 30 },
                    //{ field: 'QuotationDetailID', title: '细则ID', align: "center", width: 60 },

                    { field: 'ProductName', title: '产品名称', sortable: true, align: "center", width: 200 },
                    {
                        field: 'TechParams', title: '技术参数', align: "center", width: 200,
                        formatter: function (value, row, index) {
                            //文本超出列宽自动换行
                            //鼠标放在文本处自动显示tooltip
                            return '<span title=' + value + '>' + value + '</span>';
                        }
                    },
                    { field: 'BottleVolume', title: '规格（L）', align: "center", width: 60 },
                    { field: 'OrderCount', title: '计划数量', align: "center", width: 60 },
                     { field: 'unit', title: '单位', align: "center", width: 60 },
                    {
                        field: 'IsNewBottle', title: '是否新瓶', align: "center", width: 60,
                        editor:
                           {
                               type: "combobox",
                               options:
                                  {
                                      data: StaticCombo.isNewBottle,
                                      valueField: 'value',
                                      textField: 'text',
                                      required: true
                                  },

                           },
                        formatter: function (value, row, Index) {
                            return com.getArrayText(StaticCombo.isNewBottle, value);
                        }
                    },
                   // { field: 'SinglePrice', title: '单价', align: "center", width: 60 },
                    //{ field: 'TotalPrice', title: '总价', align: "center", width: 60 },
                    {
                        field: 'PurchaseType', title: '采购类型', align: "center", width: 100, editor: {
                            type: "validatebox",
                            options: {
                            }
                        }
                    },
                    {
                        field: 'OrderCode', title: '订单编号', align: "center", width: 100, editor: {
                            type: "validatebox",
                            options: {
                            }
                        }
                    },
                    {
                        field: 'StockCode', title: '存货编号', align: "center", width: 100, editor: {
                            type: "validatebox",
                            options: {
                            }
                        }
                    },
                    {
                        field: 'ApplyPerson', title: '使用人', align: "center", width: 60, editor: {
                            type: "validatebox",
                            options: {
                            }
                        }
                    },
                    {
                        field: 'Note', title: '备注', align: "center", width: 60, editor: {
                            type: "validatebox",
                            options: {}
                        }
                    }]],

                onAfterEdit: function (rowIndex, rowData, changes) {
                    if (editAction == "edit") {
                        com.ajax({
                            url: "/Logic/CM/QuotationAjax.aspx?method=AddProductionDetail&action=edit",
                            data: { "Id": rowData.QuotationDetailID, "PurchaseType": rowData.PurchaseType, "OrderCode": rowData.OrderCode, "StockCode": rowData.StockCode, "IsNewBottle": rowData.IsNewBottle, "ApplyPerson": rowData.ApplyPerson, "Note": rowData.Note },
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                            }
                        });
                    }
                    editRow = undefined;
                },
                onCancelEdit: function (rowIndex, rowData) {
                    $("#tbList").datagrid("rejectChanges");
                },
                onLoadSuccess: function (data) {
                },
                onClickRow: function (rowIndex) {
                    //$('#tbList').datagrid('beginEdit', e);//'beginEdit‘方法必须有一个参数
                }
            });

        })
    </script>

    <script type="text/javascript">
        editRow = undefined;
        editAction = undefined;

        //编辑
        function funcEdit() {
            var row = $('#tbList').datagrid('getSelected');

            if (row) {
                if (editRow != undefined) {
                }
                else {
                    var index = $("#tbList").datagrid('getRowIndex', row);
                    $("#tbList").datagrid('beginEdit', index);
                    editAction = "edit";
                    editRow = index;
                    rowData = $("#tbList").datagrid("getSelected");
                }
            }
            else {
                com.message("information", "请选中一行");
            }
        }

        //保存
        function funcSave() {
            var action = com.get.action;
            if (action == "add") {
                $('#tbList').datagrid('endEdit', editRow);
                var quotID = com.get.quotID;
                var prodOrderInfo = com.serializeObj("form1");
                var extend = { QuotationID: quotID, FillPerson: $("#FillPerson").textbox('getValue') }
                $.extend(prodOrderInfo, extend);
                com.ajax({
                    url: '/Logic/PM/ProductOrderAjax.aspx?method=AddProductOrder',
                    data: prodOrderInfo,
                    success: function (data) {
                        com.message(data.state, data.msg);
                        if (data.state == "success") {
                            top.wrapper.tabClosethisRefreshByTitle("报价单信息");
                        }
                    }
                });

            }
            else if (action == "edit") {
                $('#tbList').datagrid('endEdit', editRow);
            }
        }

        //取消编辑
        function funcCancel() {
            $('#tbList').datagrid("cancelEdit", editRow);
            editRow = undefined;
            editAction = undefined;
        }

        //重置
        function funcReload() {
            loadTopForm();
            $("#tbList").datagrid("reload");
            editRow = undefined;
            editAction = undefined;
        }

    </script>
</asp:Content>


<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceToorbar" runat="server">
    <a href="javascript:void(0)" id="btnSave" class="easyui-linkbutton" onclick="funcSave()"
        data-options="iconCls:'icon-save',plain:true">保存</a> &nbsp;&nbsp;
    <a href="javascript:void(0)" id="btnEdit" class="easyui-linkbutton" onclick="funcEdit()"
        data-options="iconCls:'icon-edit',plain:true">编辑</a> &nbsp;&nbsp;
    <a href="javascript:void(0)" id="btnCancel" class="easyui-linkbutton" onclick="funcCancel()"
        data-options="iconCls:'icon-redo',plain:true">取消编辑</a> &nbsp;&nbsp;
    <a href="javascript:void(0)" id="btnReset" class="easyui-linkbutton" onclick="funcReload()"
        data-options="iconCls:'icon-reload',plain:true">重置</a> &nbsp;&nbsp;
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <div id="divTotal" style="height: auto; width: 100%">
        <div id="master" class="container_16" style="height: auto">
            <form id="form1">
                <div id="title" class="grid_16" style="text-align: center">
                    <h1>生产订单</h1>
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    生产订单号 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="Code" name="Code"  disabled="disabled"/>
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    报价单号 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="QuotationCode" name="QuotationCode" class="easyui-textbox" disabled="disabled" />
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    下单日期 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="OrderDate" name="OrderDate" class="easyui-datebox" />
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    交货日期 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="ReleaseDate" name="ReleaseDate" class="easyui-datebox" />
                </div>
                <div class="Clear"></div>
                <div class="grid_2 lbl" style="text-align: right;">
                    客户单位名称 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="CustomerName" name="CustomerName" class="easyui-textbox" disabled="disabled" />
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    是否紧急 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="IsUrgent" name="IsUrgent" class="easyui-combobox"  data-options="valueField:'value',textField:'text',data:StaticCombo.isOrderUrgent,panelHeight:'auto'"  />
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    制单人 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="FillPerson" name="FillPerson" class="easyui-textbox" disabled="disabled" />
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    备注 :
                </div>
                <div class="grid_2 val" style="text-align: left;">
                    <input type="text" id="Note" name="Note" class="easyui-textbox" />
                </div>
                <div class="Clear"></div>
                <%--<div class="grid_2 lbl" style="text-align: right;">
                    送货地址 :
                </div>
                <div class="grid_6 val" style="text-align: left;">
                    <input type="text" id="ReceiveAddress" name="ReceiveAddress" class="easyui-textbox" data-options="multiline:true" style="width: 340px" disabled="disabled"/>
                </div>
                <div class="grid_2 lbl" style="text-align: right;">
                    收发票地址 :
                </div>
                <div class="grid_6 val" style="text-align: left;">
                    <input type="text" id="InvoiceAddress" name="InvoiceAddress" class="easyui-textbox" data-options="multiline:true" style="width: 340px" disabled="disabled"/>
                </div>--%>
            </form>
        </div>
    </div>
    <div id="productDetail" style="height: auto; width: 100%">
        <table id="tbList" title="产品信息" style="width: 100%">
        </table>
    </div>

    <script type="text/javascript">
        $(function () {
            var action = com.get.action;
            if (action == "edit") {
                $("#OrderDate").attr("disabled", "disabled");
                $("#ReleaseDate").attr("disabled", "disabled");
                $("#IsUrgent").attr("disabled", "disabled");
                $("#Note").attr("disabled", "disabled");
            }
        });
    </script>
</asp:Content>
